﻿@{
    ViewBag.Title = "创建同类选择窗口";
    List<SelectListItem> propertyList = new List<SelectListItem>(){
        new SelectListItem(){ Text = "所有属性", Value = ""},
        new SelectListItem(){ Text = "待审核", Value = "isLock"},
        new SelectListItem(){ Text = "已审核", Value = "unIsLock"},
        new SelectListItem(){ Text = "可评论", Value = "isMsg"},
        new SelectListItem(){ Text = "置顶", Value = "isTop"},
        new SelectListItem(){ Text = "推荐", Value = "idRed"},
        new SelectListItem(){ Text = "热门", Value = "isHot"},
        new SelectListItem(){ Text = "幻灯片", Value = "isSlide"},
    };
    int channel_id = ViewBag.ChannelId;
}
@section HeaderContent{
    <style type="text/css">
        body {margin: 10px 15px !important}
    </style>
}
<form id="form1" class="layui-form">
    <div class="div-content">
        <div id="floatHead" class="toolbar-wrap">
            <div class="toolbar">
                <div class="box-wrap">
                    <a class="menu-btn"><i class="iconfont icon-more"></i></a>
                    <div class="l-list">
                        <div class="menu-list">
                            <select class="select" name="ddlCategoryId" lay-filter="btnSearch" url="/webapi/categoryJson?id=@channel_id" selectValue="" promtion="所有类别..."><option value="">所有类别...</option></select>
                            @Html.DropDownList("ddlProperty", new SelectList(propertyList, "Value", "Text"), new { @lay_filter = "btnSearch" })
                        </div>
                    </div>
                    <div class="r-list">
                        <input type="text" id="txtKeywords" class="keyword" value="@ViewBag.Keywords" />
                        <a href="javascript:;" data-type="btnSearch" class="btn-search layui-btn"><i class="iconfont icon-search"></i></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="table-container">
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'title',templet:'#title'}">标题</th>
                        <th lay-data="{field:'CategoryTitle'}">所属类别</th>
                        <th lay-data="{field:'add_time'}">发布时间</th>
                        <th lay-data="{field:'sort_id'}">排序</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</form>
<script type="text/html" id="title">
    <a href="{{d.link_url}}" target="_blank" class="layui-table-link">{{d.title}}</a>
</script>
@section Scripts{
    <script type="text/javascript">
        var page = 1; //设置首页页码
        var limit = 10;  //设置一页显示的条数
        var total;    //总条数
        var table,form,sidername = '@ViewBag.SiderName';
        layui.use(['table','cascadeSelect','cmswh'], function () {
            table = layui.table, form = layui.form,cascadeSelect = layui.cascadeSelect,cmswh=layui.cmswh;
            cascadeSelect.init('ddlCategoryId', false);

            cmswh.dataBind('/admin/article/ArticleList?channel_id=@channel_id');
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                active[type] ? active[type].call(this) : '';
            });
            var active = {
                 btnSearch: function () {
                     table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                 }
             };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
        function submitForm(){
            var checkStatus = table.checkStatus('ltable'), data = checkStatus.data, ids = [];
            data.forEach(function (n, i) {
                ids.push(n.id);
            });
            if (ids.length == 0) {
                layer.msg("对不起，请选中您要操作的记录！");
                return false;
            }
            return ids.join(',');
        }
        function submitTbody(){
            var list = "";
            var checkStatus = table.checkStatus('ltable'), data = checkStatus.data, ids = [];
            data.forEach(function (n, i) {
                list += '<tr class="data"><td><input type="hidden" name="' + sidername + '" value="' + n.id + '">' + n.id + '</td><td>' + n.title + '</td><td><a href="javascript:;" onclick="remoreThis(this)"><i class="iconfont icon-remove"></i></a></td></tr>';
            });
            return list;
        }
        function getcond() {
            var keyword = $("#txtKeywords").val();
            var categoryId = $("#ddlCategoryId").val();
            var propertyType = $("#ddlProperty").val();
            var postdata = { keywords: keyword, property: propertyType, category_id: categoryId, channel_id:@channel_id };
            return postdata;
        }
    </script>
}